home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-21 | 5.9 KB | 240 lines | [TEXT/CWIE] |
- //===================================================================
- //======================= Headers =============================
-
- #include "Blitters.h"
- #include "GameUtilities.h"
-
- #include <string.h>
- //===================================================================
- //======================= Globals =============================
-
-
- //===================================================================
- //======================= #define =============================
-
-
- //===================================================================
- //======================= Function Prototypes =====================
-
- /*----------------------------------------------------------------------------\
-
- OffScreenBuff :: Constructor
-
- \----------------------------------------------------------------------------*/
-
- OffScreenBuff :: OffScreenBuff( void )
- {
- declared = false;
- memset( &theOffScreen , 0 , sizeof( theOffScreen ) );
- }
-
- /*----------------------------------------------------------------------------\
-
- OffScreenBuff :: Destructor
-
- \----------------------------------------------------------------------------*/
-
- OffScreenBuff :: ~OffScreenBuff( void )
- {
- DeleteBuff();
- }
-
- /*----------------------------------------------------------------------------\
-
- OffScreenBuff :: LoadPicBuff
-
- - load the off screen from a picture
-
- \----------------------------------------------------------------------------*/
-
- Boolean OffScreenBuff :: LoadPicBuff( ushort picID )
- {
- PicHandle spritePict; // the sprite picture
- CGrafPtr oldCPort; // the graf port that is in place when we are called
- GDHandle oldDevice; // the gdevice that is in place when we are called
- OSErr error;
-
-
- // load the pict
- spritePict = GetPicture( picID );
- if ( spritePict == ( PicHandle )nil )
- {
- // Warning("cant load picture" , picID );
- DebugStr( "\p LoadOffScreen " );
- Debugger();
- return false;
- }
-
- // copy its bounds rect
- theOffScreen.Bounds = RTor( ( *spritePict )->picFrame );
-
-
- /*************************************************************************/
- /* Allocate a new GWorld for the offscreen drawing and store its PixMap. */
- /*************************************************************************/
-
- error = NewGWorld( &(theOffScreen.GWorld), 16, &rToR( theOffScreen.Bounds ),
- NULL, ( GDHandle )NULL, keepLocal );//keepLocal
-
-
- if( error != noErr )
- return false;
-
-
-
- declared = true;
-
- // extract the pixmap handle
- theOffScreen.PixMap = GetGWorldPixMap( theOffScreen.GWorld );
-
- LockPixels( theOffScreen.PixMap );
- // save the current port and gdevice
- GetGWorld( &oldCPort, &oldDevice );
-
- // set the offscreen buffer as current ( and lock the pixel map )
- SetGWorld( theOffScreen.GWorld, ( GDHandle )nil );
-
- // draw the picture
- EraseRect( &( rToR( theOffScreen.Bounds ) ) );
- DrawPicture( spritePict, &( rToR( theOffScreen.Bounds ) ) );
-
- // restore the current port and gdevice
- //UnlockPixels( theOffScreen.PixMap ); rest of program assume it is locked
- SetGWorld( oldCPort, oldDevice );
-
- // dump the pict
- ReleaseResource( ( Handle )spritePict );
-
- return true;
-
- }
-
- /*----------------------------------------------------------------------------\
-
- OffScreenBuff :: NewBuff
-
- -create an empty off screen of this size
-
- \----------------------------------------------------------------------------*/
-
- Boolean OffScreenBuff :: NewBuff( const rect &size )
- {
- OSErr error;
-
- theOffScreen.Bounds = size;
-
- error = NewGWorld( &(theOffScreen.GWorld), 16, &(rToR( theOffScreen.Bounds )),
- NULL, ( GDHandle )nil, keepLocal ); //keepLocal
-
-
-
- theOffScreen.PixMap = GetGWorldPixMap( theOffScreen.GWorld );
-
- LockPixels( theOffScreen.PixMap );
-
- if( error != noErr)
- return false;
-
- declared = true;
-
- return true;
-
- }
-
- /*----------------------------------------------------------------------------\
-
- OffScreenBuff :: NewBuff
-
- -create an empty off screen of this size
-
- \----------------------------------------------------------------------------*/
-
- Boolean OffScreenBuff :: NewBuff( ushort width , ushort height )
- {
- OSErr error;
-
- theOffScreen.Bounds.left = 0;
- theOffScreen.Bounds.top = 0;
- theOffScreen.Bounds.right = width;
- theOffScreen.Bounds.bottom = height;
-
- error = NewGWorld( &(theOffScreen.GWorld), 16, &(rToR( theOffScreen.Bounds )),
- NULL, ( GDHandle )nil, keepLocal ); //keepLocal
-
-
-
- theOffScreen.PixMap = GetGWorldPixMap( theOffScreen.GWorld );
-
- LockPixels( theOffScreen.PixMap );
-
- if( error != noErr)
- return false;
-
- declared = true;
-
- return true;
-
- }
-
- /*----------------------------------------------------------------------------\
-
- OffScreenBuff :: GetSrcPtr
-
- \----------------------------------------------------------------------------*/
-
- ushort *OffScreenBuff :: GetSrcPtr( void )
- {
- return( (ushort *)(GetPixBaseAddr( theOffScreen.PixMap ) ));
- }
-
- /*----------------------------------------------------------------------------\
-
- OffScreenBuff :: GetRowSize
-
- \----------------------------------------------------------------------------*/
-
- ulong OffScreenBuff :: GetRowSize( void )
- {
- return( ( *(theOffScreen.PixMap) )->rowBytes & 0x3FFF );
- }
-
- /*----------------------------------------------------------------------------\
-
- OffScreenBuff :: GetOffScreen
-
- \----------------------------------------------------------------------------*/
-
- OffScreen *OffScreenBuff :: GetOffScreen( void )
- {
- return( &theOffScreen );
- }
-
- /*----------------------------------------------------------------------------\
-
- OffScreenBuff :: GetBoundsSize
-
- \----------------------------------------------------------------------------*/
-
- rect OffScreenBuff :: GetBoundsSize( void )
- {
- return( theOffScreen.Bounds );
- }
-
- /*----------------------------------------------------------------------------\
-
- OffScreenBuff :: DeleteBuff
-
- -checks to see if it has been declared before trying to delete it
-
- \----------------------------------------------------------------------------*/
-
- void OffScreenBuff :: DeleteBuff( void )
- {
- if( declared )
- {
- DisposeGWorld( theOffScreen.GWorld );
- declared = false;
- }
- }
-
-